-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quad shadows #1882
Quad shadows #1882
Conversation
I got a good suggestion this morning which will allow us to pack the gradient data tighter, I can do a PR with it soon. Should allow for shadow data easy peasy. The absolute max is 16 shader locations which we are hitting now, 32 bits per location. |
Ah cool, that explains it then! No rush, I know you are working on some related things so don't want to distract from that. My main motive for looking into this was to compare the performance in browsers against CSS shadows, flutter's CanvasKit renderer, etc, since shadows and motion seem to have made a comeback in UI. |
We could also save some space here by assuming the shadow color is always black and only exposing its opacity. It doesn't seem like colored shadows would be a common use-case. |
After #1885 is merged should have plenty of space in the gradient attribute to add whatever you need for this PR 👍 |
Ok I think this should be good to review now. I added some sliders for the shadow properties in the custom quad example and updated the software renderer to also support quad shadows using essentially the same sdf approach. I'm not sure if this strategy of iterating through each pixel is acceptable from a performance standpoint, but I didn't notice much difference with my slow machine- the software renderer dev build still drops frames but not the release build. There were a couple odd things I noticed (likely my own oversights as it's my first time working with tiny-skia 😅 ):
|
@nicksenger Thanks! Will take a look soon!
Lines 602 to 605 in fd07791
|
Ah thanks @hecrj , the difference I was seeing was due to the blending mode 👍 I removed the compensatory adjustments in the tiny-skia implementation and now the shadows look pretty much exactly the same when using the web-colors feature with wgpu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thank you!
I made some changes here and there to introduce a new Border
struct analogous to Shadow
for consistency.
I think we can ship this! 🚢
Woah awesome! Thanks for doing the rebase and making those changes, they make sense to me 👍 |
This PR adds the options of specifying a
Shadow
for quads having some color, offset and softness:The custom quad example is updated to have a shadow:
Some things don't work yet:
vertex buffer stride exceeds limit
on WASM builds. Maybe there is a straightforward way to increase this limit but I couldn't find it (not that familiar with wgpu)